#!/usr/bin/perl -w

BEGIN {
	push @INC,"/usr/local/cluster/lib/perl";
}

use Sys::Hostname;
use Data::Dumper;
use English;
use XML::Simple;
use Getopt::Long;
use File::Basename;
use cld_client;
use clutils;
use cldlockc;
use lvm;
use clnet qw(CLNET_assign_ips CLNET_unassign_ips CLNET_check_ping
		CLNET_return_network_static_ip);

$_PRG=basename($0);

$ARG_application=undef;

Getopt::Long::Configure("no_ignore_case");
if(!GetOptions(
	"application|A=s"	=> \$ARG_application)) {
	exit(1);
}

exit(1) if !defined($ARG_application);
$ARG_config="/etc/cluster/clconf.xml";
if(! -f "/etc/cluster/$ARG_application/appconf.xml") {
	exit(1);
}

($xml,$err,@errmsg)=validate_cluster_cfg($ARG_config,1);
if(!defined($xml)) {exit(1)};
($xml2,$err,@errmsg)=validate_application_cfg($ARG_application,1);
if(!defined($xml2)) {exit(1);}

($res,@errs)=CLNET_assign_ips(xml=>$xml,appxml=>$xml2);
exit(1) if !$res;
exit(1) if @errs;
exit(0);
